<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>用户中心</title>
<link rel="stylesheet"	href="${basePath }static/bootstrap-3.3.7/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="${basePath }static/css/cwx/perinfo.css" />
</head>
<%
	String buttonValue = request.getParameter("name");
%>
<body id="perbody">
<!-- 隐藏内容 -->
<input type="hidden" id="usertel" name="usertel" value="<%=session.getAttribute("userTel") %>" />

	<form id="infoform" action="ChangUsermessage" method="post">
<!-- 	method="post" action="PerinfoAction" -->
		<ul>
			<li>
				<div id="perdiv">
					<span name="usertel">用户账号：</span>
					<span style="margin-left:10px"><%=session.getAttribute("userTel") %></span>
				</div>
			</li>
			<li>
				<div id="perdiv">
					<span>用户昵称：</span> <input type="text" id="username" name="username"style="margin-left:10px">
				</div>
			</li>
			<li>
				<div id="perdiv">
					<span>性别：</span> <input type="text" id="usersex" name="usersex" style="margin-left:46px">
				</div>
			</li>
			<li>

			</li>
			<li>
				<div id="perdiv">
					<span>真实姓名：</span> <input type="text" name="userrealname" id="userrealname"style="margin-left:10px">
				</div>
			</li>
			<li>
				<div id="perdiv">
					<span>身份证号：</span> <input type="text" name="useridcard" id="useridcard"style="margin-left:10px">
				</div>
			</li>
		</ul>
		<div id="perdiv">
			<button type="submit" class="btn btn-danger" id="修改"  onclick="return subInfo()">修改</button>
		</div>
	</form>
</body>
<script type="text/javascript"	src="${basePath }static/js/HomePageJs/iquery-1.12.4/jquery-1.12.4.min.js"></script>
<script type="text/javascript"	src="${basePath }static/js/HomePageJs/layer-v3.1.1/layer/layer.js"></script>
<script type="text/javascript">
	function subInfo() {
		// 错误提示信息
		var strMsg = "";
		// 用户名验证
		var regName = /^.\S{3,5}$/;
		var username = document.getElementById("username").value;
		if (username == null || username == ""
				|| regName.test(username) === false) {
			// 增加提示信息
			strMsg += "请输入用户名!<br>";
		}
		// 真实姓名验证
		var userrealname = document.getElementById("userrealname").value;
		if (userrealname == null || userrealname == "") {
			// 增加提示信息
			strMsg += "请输入真实姓名!<br>";
		}
		// 性别验证
		var usersex = document.getElementById("usersex").value;
		if (usersex == null || usersex == "") {
			// 增加提示信息
			strMsg += "请输入性别!<br>";
		}
		if (usersex != "男"&& usersex != "女") {
			// 增加提示信息
			strMsg += "请输入正确的性别!<br>";
		}
		// 身份证号验证
		var regId = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
		var useridcard = document.getElementById("useridcard").value;
		if (useridcard == null || useridcard == ""
				|| regId.test(useridcard) === false) {
			// 增加提示信息
			strMsg += "请输入正确的身份证号!<br>";
		}
		if (strMsg == "") {
			// 验证通过
			layer.open({
				title : '提示',
				content : '修改成功'
				
			});
			return true;
		} else {
			// 验证不通过
			layer.open({
				title : '提示',
				content : strMsg
			});
			return false;
		}

	}
	function doSubmit() {
		document.getElementById("infoform").submit();
	}
</script>

<script type="text/javascript">
$(function(){
	
	$.ajax({
			type : "POST", // 请求类型
			url : "UserMessage", // 请求的url
			data : "usertel=" + $("#usertel").val(),
			// 			dataType : "json",
			success : function(data, textStatus, jqXHR) { // 执行成功之后的回调函数
				console.info(data);
				// 回调函数的dom操作
				
				$.each(data,function(index, eachVal) {
					
				document.getElementById("username").value = eachVal.username;
				document.getElementById("usersex").value = eachVal.usersex;
				document.getElementById("userrealname").value = eachVal.userrealname;
				document.getElementById("useridcard").value = eachVal.useridcard;
							
				})
			},
			error : function(data) {
				alert("请求失败" + data);
			}
		});
	
	//在真实姓名的输入框中不会出现null
	if($("#userrealname").val()===null||$("#userrealname").val() == "undefined"){
		$("#userrealname").val("");
	}
	//身份证号的输入框中不会出现null
	if($("#useridcard").val()===null||$("#useridcard").val() == "undefined"){
		$("#useridcard").val("");
	}
	
})
</script>
</html>